package org.hq.controller;

import com.alibaba.fastjson2.JSON;
import org.hq.services.UpVideoService;
import org.hq.upvideo.RedisKey;
import org.hq.upvideo.VideoTaskEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Set;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

@RestController
@RequestMapping("/up")
public class Up {
    private boolean start = true;
    @Autowired
    private UpVideoService ups;
    @Autowired
    RedisTemplate<String, String> redisString;
    private final ExecutorService exec = Executors.newFixedThreadPool(32);

    @GetMapping("/finish")
    public String finish() {
     ups.finish();
       //
        return "finish";
    }

    @GetMapping("/update")
    public String update() {
        ups.update();
        //cpvideoInfo
        return "finish";
    }
    @GetMapping("/cpvideoInfo")
    public String cpvideoInfo() {
        String keyadd= String.valueOf(RedisKey.ADD_VIDEO_ITEM_SIHU_KEY);
        Set set = redisString.opsForSet().members(keyadd);
        System.out.println(set.size());
        for(Object o : set){
            String json= (String) o;
            VideoTaskEntity entity = JSON.parseObject(json, VideoTaskEntity.class);
            ups.submit(entity);
        }
        return "cpvideoInfo";
    }


    @GetMapping("/tostring")
    public String tostring() {

        //cpvideoInfo
        return "tostring";
    }

}
